const checkCity = require('../../../utils/checkCity.js');
const api = require('../../../utils/api.js');
Page({
  data: {
    params: {
      aid: 3,
      pid: 1
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2
      })
    }
    var list = [{
      "title": that.data.params.type + "加载的的数据",
      "adress": "鼓楼区",
      "type": "日结",
      "tips": ["供吃", "供住", "aaa"],
      "pay": "17元/小时",
      "time": "45分钟前",
      "jobid": 193,
      "isget": 1,
    }, {
      "title": that.data.params.type + "加载的的数据",
      "adress": "鼓楼区",
      "type": "日结",
      "tips": ["供吃", "供住", "aaa"],
      "pay": "17元/小时",
      "jobid": 193,
      "isget": 0,
    }
    ];
    that.setData({
      jobList: list,
      params: {
        aid: 1,
        pid: 1
      }
    })
    // checkCity.check(function (city) {
    //   that.data.params.type = "onLoad任务";
    //   that.data.params.city = city.fullname;
    //   api._get('api/books', that.data.params).then(res => {
    //     that.data.params.pid = 2;
    //     that.setData({
    //       jobList: res,
    //       params: that.data.params
    //     })
    //   })
    // });
  },
  onReachBottom() {
    const that = this;
    that.data.params.type = "ReachBottom任务";
    api._get('api/books', that.data.params).then(res => {
      that.data.params.pid = that.data.params.pid + 1;
      that.setData({
        jobList: that.data.jobList.concat(res),
        params: that.data.params
      })
    })
  },
  onPullDownRefresh() {
    const that = this;
    that.data.params.type = "DownRefresh任务";
    that.data.params.pid = 1;
    api._get('api/books', that.data.params).then(res => {
      that.data.params.pid = 2;
      that.setData({
        jobList: res,
        params: that.data.params
      })
      wx.stopPullDownRefresh()
    })
  },
})